/**
 * Created by mango on 2017/3/3.
 */
module.exports = {

    key: "request-example",
    desc:"请求",
    create: function (content) {
        var list = [
            this.head(),
            content[this.key] ? this.content(content[this.key]) : ""
        ];
        return list.join("\r\n\r\n");
    }, head: function () {
        return "**" + this.desc + "示例：**";
    }, content: function (content) {

        var list = [this.code()];


        if (content) {
            list.push(this.getNullLine(0) + "{");
            this.getJSon(content, 1, list);

        }


        list.push(this.code());
        return list.join("\r\n")


    },
    code: function () {
        return "```";
    },
    getNullLine: function (line) {
        var str = "";
        var split = "  ";
        for (var i = 0; i <= line; i++) {
            str += split;

        }
        return str;
    }, getJSon(obj, index, list){

        for (let key in obj) {
            if (typeof obj[key] == "object") {
                list.push(this.getNullLine(index) + "\"" + key + "\": " + "{");
                this.getJSon(obj[key], index + 1, list);
            } else {
                list.push(this.getNullLine(index) + ("\"" + key + "\": " + "\"" + obj[key] + "\"" ) + ",");
            }
        }
        list.push(this.getNullLine(index) + "}");
    }
}